package config

import (
	"fmt"
	"newsletter-subs/pkg/model"

	"github.com/spf13/viper"
)

var ConfigVar Config

type Config struct {
	DB    model.ConfigDB    `json: "db"`
	Redis model.ConfigRedis `json:"redis"`
}

func Init() {
	//load config file
	viperConfig := viper.New()
	viperConfig.SetConfigFile("./config/app.yml")
	err := viperConfig.ReadInConfig()
	if err != nil {
		panic(err)
	}

	fmt.Println("read app.yml successfully")

	if err := viperConfig.Unmarshal(&ConfigVar); err != nil {
		fmt.Printf("配置映射错误,%v\n", err)
	}
	fmt.Printf("DB: %+v\n", ConfigVar.DB)
	fmt.Printf("Redis: %+v\n", ConfigVar.Redis)

}
